<template>
  <div class="privilegecreate">
    <div
      class="header"
      style="height: 50px; margin-top: 10px; margin-left: 20px"
    >
      <el-page-header @back="goBack"></el-page-header>
    </div>
    <div class="form">
      <el-form label-width="200px" class="demo-ruleForm">
        <el-form-item label="名称" style="width: 50%">
          <el-input v-model="form.name"></el-input>
        </el-form-item>
        <el-form-item label="route">
          <el-cascader
            v-model="form.route"
            :options="options"
            :props="{ expandTrigger: 'hover' }"
            @change="handleChange"
          ></el-cascader>
        </el-form-item>
        <el-form-item label="描述" style="width: 70%">
          <el-input
            type="textarea"
            :rows="7"
            v-model="form.description"
          ></el-input>
        </el-form-item>
        <el-form-item>
          <el-button type="primary" @click="submitHandler">立即创建</el-button>
        </el-form-item>
      </el-form>
    </div>
  </div>
</template>
<script>
import { post } from "@/utils/request";
export default {
  data() {
    return {
      form: {},
      value: [],
        options: [{
          value: 'sys',
          label: '/sys',
          children: [{
            value: 'user',
            label: '/user',
            children: [{
              value: 'List',
              label: '/List'
            }, {
              value: 'Detail',
              label: '/Detail'
            }, {
              value: 'Personal',
              label: '/Personal'
            }]
          }, {
            value: 'privilege',
            label: '/privilege',
            children: [{
              value: 'List',
              label: '/List'
            }]
          },{
            value: 'role',
            label: '/role',
            children: [{
              value: 'List',
              label: '/List'
            }]
          }]
        }, {
          value: 'info',
          label: '/info',
          children: [{
            value: 'category',
            label: '/category',
            children: [{
              value: 'List',
              label: '/List'
            },]
          }, {
            value: 'article',
            label: '/article',
            children: [{
              value: 'List',
              label: '/List'
            },{
              value: 'Edit',
              label: '/Edit'
            },{
              value: 'Details',
              label: '/Details'
            }]
          },]
        }, {
          value: 'greenhouse',
          label: '/greenhouse',
          children: [{
            value: 'application',
            label: '/application',
            children: [{
              value: 'List',
              label: '/List'
            }, {
              value: 'Create',
              label: '/Create'
            }]
          }, {
            value: 'module',
            label: '/module',
            children: [{
              value: 'List',
              label: '/List'
            }, {
              value: 'Create',
              label: '/Create'
            }, {
              value: 'Publish',
              label: '/Publish'
            }, {
              value: 'Train',
              label: '/Train'
            }, {
              value: 'Evaluation',
              label: '/Evaluation'
            }]
          }, {
            value: 'api',
            label: '/api',
            children: [{
              value: 'List',
              label: '/List'
            }, {
              value: 'Test',
              label: '/Test'
            }]
          }, {
            value: 'Professor',
            label: '/Professor'
          }, {
            value: 'Question',
            label: '/Question'
          }, {
            value: 'replay',
            label: '/replay'
          }, {
            value: 'MyQuestion',
            label: '/MyQuestion'
          }]
        },{
          value: 'file',
          label: '/file',
          children: [{
            value: 'datasetL',
            label: '/datasetL',
            children: [{
              value: 'List',
              label: '/List'
            }]
          },]
        },{
          value: 'Logs',
          label: '/Logs',
          children: [{
            value: 'List',
            label: '/List'
          },]
        }],
    };
  },
  created() {
    this.form = this.$route.query;
  },
  methods: {
    handleChange(value) {
        console.log(value);
      },
    submitHandler() {
      let url = "http://39.106.31.187:8888/basePrivilege/saveOrUpdate";
      post(url, this.form).then((resp) => {
        this.$message({ type: "success", message: resp.message });
        this.goBack();
      });
    },
    goBack() {
      this.$router.back();
    },
  },
};
</script>